package com.dynamixsoftware.printershare.smb.ntlmssp;

import com.dynamixsoftware.printershare.smb.NtlmPasswordAuthentication;
import com.dynamixsoftware.printershare.smb.netbios.NbtAddress;
import com.dynamixsoftware.printershare.smb.util.Dumper;
import com.dynamixsoftware.printershare.smb.util.HMACT64;
import com.dynamixsoftware.printershare.smb.util.MD4;
import com.dynamixsoftware.printershare.smb.util.RC4;
import java.io.IOException;
import java.net.UnknownHostException;
import java.security.SecureRandom;
import java.util.Arrays;

public class Type3Message
  extends NtlmMessage
{
  private static final String DEFAULT_DOMAIN;
  private static final int DEFAULT_FLAGS = 0;
  private static final String DEFAULT_USER;
  private static final String DEFAULT_WORKSTATION;
  private static final int LM_COMPATIBILITY = 3;
  private static final long MILLISECONDS_BETWEEN_1970_AND_1601 = 11644473600000L;
  private static final SecureRandom RANDOM = new SecureRandom();
  private String domain;
  private byte[] lmResponse;
  private byte[] masterKey = null;
  private byte[] ntResponse;
  private byte[] sessionKey = null;
  private String user;
  private String workstation;
  
  static
  {
    DEFAULT_FLAGS = 513;
    DEFAULT_DOMAIN = null;
    DEFAULT_USER = null;
    try
    {
      String str2 = NbtAddress.getLocalHost().getHostName();
      str1 = str2;
    }
    catch (UnknownHostException localUnknownHostException)
    {
      for (;;)
      {
        String str1 = null;
      }
    }
    DEFAULT_WORKSTATION = str1;
  }
  
  public Type3Message()
  {
    setFlags(getDefaultFlags());
    setDomain(getDefaultDomain());
    setUser(getDefaultUser());
    setWorkstation(getDefaultWorkstation());
  }
  
  public Type3Message(Type2Message paramType2Message, String paramString1, String paramString2, String paramString3, String paramString4, int paramInt)
  {
    setFlags(paramInt | getDefaultFlags(paramType2Message));
    if (paramString4 == null) {
      paramString4 = getDefaultWorkstation();
    }
    setWorkstation(paramString4);
    setDomain(paramString2);
    setUser(paramString3);
    switch (LM_COMPATIBILITY)
    {
    default: 
      setLMResponse(getLMResponse(paramType2Message, paramString1));
      setNTResponse(getNTResponse(paramType2Message, paramString1));
    }
    byte[] arrayOfByte1;
    do
    {
      byte[] arrayOfByte7;
      byte[] arrayOfByte8;
      do
      {
        return;
        if ((0x80000 & getFlags()) == 0)
        {
          setLMResponse(getLMResponse(paramType2Message, paramString1));
          setNTResponse(getNTResponse(paramType2Message, paramString1));
          return;
        }
        arrayOfByte7 = new byte[24];
        RANDOM.nextBytes(arrayOfByte7);
        Arrays.fill(arrayOfByte7, 8, 24, (byte)0);
        arrayOfByte8 = NtlmPasswordAuthentication.nTOWFv1(paramString1);
        byte[] arrayOfByte9 = NtlmPasswordAuthentication.getNTLM2Response(arrayOfByte8, paramType2Message.getChallenge(), arrayOfByte7);
        setLMResponse(arrayOfByte7);
        setNTResponse(arrayOfByte9);
      } while ((0x10 & getFlags()) != 16);
      byte[] arrayOfByte10 = new byte[16];
      System.arraycopy(paramType2Message.getChallenge(), 0, arrayOfByte10, 0, 8);
      System.arraycopy(arrayOfByte7, 0, arrayOfByte10, 8, 8);
      MD4 localMD4 = new MD4();
      localMD4.update(arrayOfByte8);
      HMACT64 localHMACT642 = new HMACT64(localMD4.digest());
      localHMACT642.update(arrayOfByte10);
      byte[] arrayOfByte11 = localHMACT642.digest();
      if ((0x40000000 & getFlags()) != 0)
      {
        this.masterKey = new byte[16];
        RANDOM.nextBytes(this.masterKey);
        byte[] arrayOfByte12 = new byte[16];
        new RC4(arrayOfByte11).update(this.masterKey, 0, 16, arrayOfByte12, 0);
        setSessionKey(arrayOfByte12);
        return;
      }
      this.masterKey = arrayOfByte11;
      setSessionKey(this.masterKey);
      return;
      byte[] arrayOfByte6 = getNTResponse(paramType2Message, paramString1);
      setLMResponse(arrayOfByte6);
      setNTResponse(arrayOfByte6);
      return;
      arrayOfByte1 = NtlmPasswordAuthentication.nTOWFv2(paramString2, paramString3, paramString1);
      byte[] arrayOfByte2 = new byte[8];
      RANDOM.nextBytes(arrayOfByte2);
      setLMResponse(getLMv2Response(paramType2Message, paramString2, paramString3, paramString1, arrayOfByte2));
      byte[] arrayOfByte3 = new byte[8];
      RANDOM.nextBytes(arrayOfByte3);
      setNTResponse(getNTLMv2Response(paramType2Message, arrayOfByte1, arrayOfByte3));
    } while ((0x10 & getFlags()) != 16);
    HMACT64 localHMACT641 = new HMACT64(arrayOfByte1);
    localHMACT641.update(this.ntResponse, 0, 16);
    byte[] arrayOfByte4 = localHMACT641.digest();
    if ((0x40000000 & getFlags()) != 0)
    {
      this.masterKey = new byte[16];
      RANDOM.nextBytes(this.masterKey);
      byte[] arrayOfByte5 = new byte[16];
      new RC4(arrayOfByte4).update(this.masterKey, 0, 16, arrayOfByte5, 0);
      setSessionKey(arrayOfByte5);
      return;
    }
    this.masterKey = arrayOfByte4;
    setSessionKey(this.masterKey);
  }
  
  private static String getDefaultDomain()
  {
    return DEFAULT_DOMAIN;
  }
  
  private static int getDefaultFlags()
  {
    return DEFAULT_FLAGS;
  }
  
  private static int getDefaultFlags(Type2Message paramType2Message)
  {
    if (paramType2Message == null) {
      return DEFAULT_FLAGS;
    }
    if ((0x1 & paramType2Message.getFlags()) != 0) {}
    for (int i = 1;; i = 2) {
      return 0x200 | i;
    }
  }
  
  private static String getDefaultUser()
  {
    return DEFAULT_USER;
  }
  
  private static String getDefaultWorkstation()
  {
    return DEFAULT_WORKSTATION;
  }
  
  private static byte[] getLMResponse(Type2Message paramType2Message, String paramString)
  {
    if ((paramType2Message == null) || (paramString == null)) {
      return null;
    }
    return NtlmPasswordAuthentication.getPreNTLMResponse(paramString, paramType2Message.getChallenge());
  }
  
  private static byte[] getLMv2Response(Type2Message paramType2Message, String paramString1, String paramString2, String paramString3, byte[] paramArrayOfByte)
  {
    if ((paramType2Message == null) || (paramString1 == null) || (paramString2 == null) || (paramString3 == null) || (paramArrayOfByte == null)) {
      return null;
    }
    return NtlmPasswordAuthentication.getLMv2Response(paramString1, paramString2, paramString3, paramType2Message.getChallenge(), paramArrayOfByte);
  }
  
  private static byte[] getNTLMv2Response(Type2Message paramType2Message, byte[] paramArrayOfByte1, byte[] paramArrayOfByte2)
  {
    if ((paramType2Message == null) || (paramArrayOfByte1 == null) || (paramArrayOfByte2 == null)) {
      return null;
    }
    long l = 10000L * (11644473600000L + System.currentTimeMillis());
    return NtlmPasswordAuthentication.getNTLMv2Response(paramArrayOfByte1, paramType2Message.getChallenge(), paramArrayOfByte2, l, paramType2Message.getTargetInformation());
  }
  
  private static byte[] getNTResponse(Type2Message paramType2Message, String paramString)
  {
    if ((paramType2Message == null) || (paramString == null)) {
      return null;
    }
    return NtlmPasswordAuthentication.getNTLMResponse(paramString, paramType2Message.getChallenge());
  }
  
  public String getDomain()
  {
    return this.domain;
  }
  
  public byte[] getLMResponse()
  {
    return this.lmResponse;
  }
  
  public byte[] getMasterKey()
  {
    return this.masterKey;
  }
  
  public byte[] getNTResponse()
  {
    return this.ntResponse;
  }
  
  public byte[] getSessionKey()
  {
    return this.sessionKey;
  }
  
  public String getUser()
  {
    return this.user;
  }
  
  public String getWorkstation()
  {
    return this.workstation;
  }
  
  public void setDomain(String paramString)
  {
    this.domain = paramString;
  }
  
  public void setLMResponse(byte[] paramArrayOfByte)
  {
    this.lmResponse = paramArrayOfByte;
  }
  
  public void setNTResponse(byte[] paramArrayOfByte)
  {
    this.ntResponse = paramArrayOfByte;
  }
  
  public void setSessionKey(byte[] paramArrayOfByte)
  {
    this.sessionKey = paramArrayOfByte;
  }
  
  public void setUser(String paramString)
  {
    this.user = paramString;
  }
  
  public void setWorkstation(String paramString)
  {
    this.workstation = paramString;
  }
  
  public byte[] toByteArray()
  {
    int j;
    try
    {
      i = getFlags();
      if ((i & 0x1) == 0) {
        break label473;
      }
      j = 1;
    }
    catch (IOException localIOException)
    {
      int i;
      String str2;
      byte[] arrayOfByte1;
      int k;
      String str3;
      byte[] arrayOfByte2;
      int n;
      throw new IllegalStateException(localIOException.getMessage());
    }
    str2 = getDomain();
    arrayOfByte1 = null;
    if (str2 != null)
    {
      k = str2.length();
      arrayOfByte1 = null;
      if (k != 0)
      {
        if (j == 0) {
          break label380;
        }
        arrayOfByte1 = str2.getBytes("UTF-16LE");
      }
    }
    label58:
    int m;
    if (arrayOfByte1 != null)
    {
      m = arrayOfByte1.length;
      label68:
      str3 = getUser();
      arrayOfByte2 = null;
      if (str3 != null)
      {
        n = str3.length();
        arrayOfByte2 = null;
        if (n != 0)
        {
          if (j == 0) {
            break label392;
          }
          arrayOfByte2 = str3.getBytes("UTF-16LE");
        }
      }
      label110:
      if (arrayOfByte2 == null) {
        break label484;
      }
    }
    label162:
    label172:
    label188:
    label204:
    label220:
    label476:
    label484:
    for (int i1 = arrayOfByte2.length;; i1 = 0)
    {
      String str4 = getWorkstation();
      Object localObject = null;
      if (str4 != null)
      {
        int i2 = str4.length();
        localObject = null;
        if (i2 != 0)
        {
          if (j == 0) {
            break label407;
          }
          localObject = str4.getBytes("UTF-16LE");
        }
      }
      int i3;
      int i4;
      int i5;
      int i6;
      if (localObject != null)
      {
        i3 = localObject.length;
        byte[] arrayOfByte3 = getLMResponse();
        if (arrayOfByte3 == null) {
          break label432;
        }
        i4 = arrayOfByte3.length;
        byte[] arrayOfByte4 = getNTResponse();
        if (arrayOfByte4 == null) {
          break label438;
        }
        i5 = arrayOfByte4.length;
        byte[] arrayOfByte5 = getSessionKey();
        if (arrayOfByte5 == null) {
          break label444;
        }
        i6 = arrayOfByte5.length;
        byte[] arrayOfByte6 = new byte[i6 + (i5 + (i4 + (i3 + (i1 + (m + 64)))))];
        System.arraycopy(NTLMSSP_SIGNATURE, 0, arrayOfByte6, 0, 8);
        writeULong(arrayOfByte6, 8, 3);
        writeSecurityBuffer(arrayOfByte6, 12, 64, arrayOfByte3);
        int i7 = 64 + i4;
        writeSecurityBuffer(arrayOfByte6, 20, i7, arrayOfByte4);
        int i8 = i7 + i5;
        writeSecurityBuffer(arrayOfByte6, 28, i8, arrayOfByte1);
        int i9 = i8 + m;
        writeSecurityBuffer(arrayOfByte6, 36, i9, arrayOfByte2);
        int i10 = i9 + i1;
        writeSecurityBuffer(arrayOfByte6, 44, i10, (byte[])localObject);
        writeSecurityBuffer(arrayOfByte6, 52, i10 + i3, arrayOfByte5);
        writeULong(arrayOfByte6, 60, i);
        return arrayOfByte6;
      }
      for (;;)
      {
        String str1 = getOEMEncoding();
        break;
        label380:
        arrayOfByte1 = str2.getBytes(str1);
        break label58;
        arrayOfByte2 = str3.toUpperCase().getBytes(str1);
        break label110;
        byte[] arrayOfByte7 = str4.toUpperCase().getBytes(str1);
        localObject = arrayOfByte7;
        break label162;
        i3 = 0;
        break label172;
        i4 = 0;
        break label188;
        i5 = 0;
        break label204;
        i6 = 0;
        break label220;
        for (;;)
        {
          if (j == 0) {
            break label476;
          }
          str1 = null;
          break;
          j = 0;
        }
      }
      m = 0;
      break label68;
    }
  }
  
  public String toString()
  {
    String str1 = getUser();
    String str2 = getDomain();
    String str3 = getWorkstation();
    byte[] arrayOfByte1 = getLMResponse();
    byte[] arrayOfByte2 = getNTResponse();
    byte[] arrayOfByte3 = getSessionKey();
    StringBuilder localStringBuilder1 = new StringBuilder().append("Type3Message[domain=").append(str2).append(",user=").append(str1).append(",workstation=").append(str3).append(",lmResponse=");
    String str4;
    String str5;
    label113:
    StringBuilder localStringBuilder3;
    if (arrayOfByte1 == null)
    {
      str4 = "null";
      StringBuilder localStringBuilder2 = localStringBuilder1.append(str4).append(",ntResponse=");
      if (arrayOfByte2 != null) {
        break label206;
      }
      str5 = "null";
      localStringBuilder3 = localStringBuilder2.append(str5).append(",sessionKey=");
      if (arrayOfByte3 != null) {
        break label239;
      }
    }
    label206:
    label239:
    for (String str6 = "null";; str6 = "<" + arrayOfByte3.length + " bytes>")
    {
      return str6 + ",flags=0x" + Dumper.toHexString(getFlags(), 8) + "]";
      str4 = "<" + arrayOfByte1.length + " bytes>";
      break;
      str5 = "<" + arrayOfByte2.length + " bytes>";
      break label113;
    }
  }
}


/* Location:           C:\Users\Admin\Desktop\Decompiler\JAD\jd-gui-0.3.6.windows\classes_dex2jar.jar
 * Qualified Name:     com.dynamixsoftware.printershare.smb.ntlmssp.Type3Message
 * JD-Core Version:    0.7.0.1
 */